package com.controller;

import com.Service.MedicalCardService;
import com.model.pojo.MedicalCard;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("Initialize")
public class MedicalCardController {
@Resource
    private MedicalCardService medicalCardService;
    @RequestMapping("Initialize")
    public String Initialize(){

        return "MedicalCard";
    }


    @RequestMapping("settlement")
    public String settlement(HttpSession session, HttpServletRequest request,  String cardid,String price,String listingSerialNumber){
        session.removeAttribute("yue");



        MedicalCard medicalCard= medicalCardService.settlement(Integer.valueOf(price),cardid,listingSerialNumber,session);

            String message=(String) session.getAttribute("yue");
        if(message!=null){


            if(message.equals("余额不足")){
                session.setAttribute("medicalCard",medicalCard);
                return "listtingList";
            }else{

                session.setAttribute("medicalCard","缴费成功");
            }

        }

      return "redirect:/Listing/Listing";

    }
    @RequestMapping("amount")
    public String amount(HttpSession session, HttpServletRequest request,  String cardid1,double amount,double price,String listingSerialNumber){
        session.removeAttribute("yue");

        if(amount>0){
            amount=amount+price;
            boolean bl= medicalCardService.amount(cardid1,amount);
            session.setAttribute("judge","成功了");
            return "redirect:/Listing/listOfPayCost?listingSerialNumber="+listingSerialNumber;
        }else{
            session.setAttribute("judge","失败了");

        }

      return "listtingList";
    }
}
